#ifndef WALKIETALKIE_HPP_
# define WALKIETALKIE_HPP_

# include "Message.hpp"
# include "Wrappers/UnixUtils/NamedPipe.hpp"
# include "Utils/macros.hpp"

namespace pizzeria {
namespace communication {

/* Handle the communication between two \a WalkieTalkie object.
 * Data are send through Unix FIFO (named pipe).
 */
class WalkieTalkie {
public:
  /*! Default constructor */
  WalkieTalkie();
  /*! Destructor */
  ~WalkieTalkie();

  /*! Link this WalkieTalkie (A) with the given WalkieTalkie (B)
   * A.input = B.output
   * A.output = B.input
   * \param walkieB : the WalkieTalkie to be linked with
   */
  void LinkWith(WalkieTalkie &walkieB);
  /*! Send a message to the linked WalkieTalkie
   * \data message : the message to send (see struct Messsage)
   * \throw std::invalid_argument if there is no linked WalkieTalkie
   */
  void Send(const Message &message) const;
  /* Receive message send by the linked WalkieTalkie
   * \return the first message to read if any, otherwise return a message
   * of type NONE
   */
  Message Receive() const;

  /*! Get input FIFO
   * \return input FIFO
   */
  wrappers::unix_utils::NamedPipe*& GetInput();
  /*! Set output FIFO
   * \param output : output FIFO
   */
  void SetOutput(wrappers::unix_utils::NamedPipe*& output);

private:
  /*! Disallow copy constructor and assignment operator */
  DISALLOW_COPY_AND_ASSIGN(WalkieTalkie);

  wrappers::unix_utils::NamedPipe *mInput; /*!< Input FIFO */
  wrappers::unix_utils::NamedPipe *mOutput; /*!< Output FIFO */
};

} /* !namespace communication */
} /* !namespace pizzeria */
#endif /* !WALKIETALKIE_HPP_ */
